Description:
DIH detects declarations that hide other visible declarations. These are:
Local variables or method parameters that shadow fields
of the containing class. As far as it is common practice
in constructors to use formal parameters with the same name as
class components, DIH detects situations where a class field is
explicitly accessed by using
this
reference and does not produce
a warning message in this case.
When the option Include inherited fields is set in the audit properties, DIH considers
not only fields declared by a class, but also all of the inherited ones.
static
methods declared in superclasses.
Incorrect:
public class Container {
private int size;
public void copyFrom(Container c) {
int size = c.size;
...
}
}
Correct:
public class Container {
private int size;
public void copyFrom(Container c) {
int newSize = c.size;
...
}
}
Incorrect:
public class Window {
protected int style;
public static Window Create(...) {
...
}
}
public class Button : Window {
protected int style;
public static Button Create(...) {
...
}
}
Correct:
public class Window {
protected int style;
public static Window CreateWindow(...) {
...
}
}
public class Button : Window {
protected int extendedStyle;
public static Button CreateButton(...) {
...
}
}
Refactoring: